package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TStockin;
import com.ruoyi.system.domain.TStockroom;
import com.ruoyi.system.service.ITStockinService;
import com.ruoyi.system.service.ITStockroomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 入库管理Controller
 * 
 * @author ruoyi
 * @date 2024-05-08
 */
@RestController
@RequestMapping("/system/stockin")
public class TStockinController extends BaseController
{
    @Autowired
    private ITStockinService tStockinService;
    @Autowired
    private ITStockroomService tStockroomService;
    /**
     * 查询所有仓库信息
     */
    @GetMapping("/stockList")
    public AjaxResult stockList(TStockroom tStockroom)
    {
        //查询所有仓库
        List<TStockroom> list = tStockroomService.selectTStockroomList(tStockroom);
        return success(list);
    }
    /**
     * 查询入库管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:stockin:list')")
    @GetMapping("/list")
    public TableDataInfo list(TStockin tStockin)
    {
        startPage();
        List<TStockin> list = tStockinService.selectTStockinList(tStockin);
        return getDataTable(list);
    }

    /**
     * 导出入库管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:stockin:export')")
    @Log(title = "入库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TStockin tStockin)
    {
        List<TStockin> list = tStockinService.selectTStockinList(tStockin);
        ExcelUtil<TStockin> util = new ExcelUtil<TStockin>(TStockin.class);
        util.exportExcel(response, list, "入库管理4数据");
    }

    /**
     * 获取入库管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:stockin:query')")
    @GetMapping(value = "/{stockinId}")
    public AjaxResult getInfo(@PathVariable("stockinId") Long stockinId)
    {
        return success(tStockinService.selectTStockinByStockinId(stockinId));
    }

    /**
     * 新增入库管理
     */
    @PreAuthorize("@ss.hasPermi('system:stockin:add')")
    @Log(title = "入库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TStockin tStockin)
    {
        return toAjax(tStockinService.insertTStockin(tStockin));
    }

    /**
     * 修改入库管理
     */
    @PreAuthorize("@ss.hasPermi('system:stockin:edit')")
    @Log(title = "入库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TStockin tStockin)
    {
        return toAjax(tStockinService.updateTStockin(tStockin));
    }

    /**
     * 删除入库管理
     */
    @PreAuthorize("@ss.hasPermi('system:stockin:remove')")
    @Log(title = "入库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stockinIds}")
    public AjaxResult remove(@PathVariable Long[] stockinIds)
    {
        return toAjax(tStockinService.deleteTStockinByStockinIds(stockinIds));
    }
}
